//
//  ABCViewController.m
//  SmartLife
//
//  Created by Lawrence on 15/10/29.
//  Copyright © 2015年 Lawrence. All rights reserved.
//

#import "ABCIntroduceViewController.h"



@interface ABCIntroduceViewController()<UIScrollViewDelegate>

@property(strong,nonatomic) UIScrollView *scrollView;
@property(strong,nonatomic) UIPageControl *pageControl;
@property(strong,nonatomic) UIButton *donButton;


@property(strong,nonatomic) UIView *viewOne;
@property(strong,nonatomic) UIView *viewTwo;
@property(strong,nonatomic) UIView *viewThree;
@property(strong,nonatomic) UIView *viewFour;


@end
@implementation ABCIntroduceViewController

-(instancetype)initWithFrame:(CGRect)frame{
    self=[super initWithFrame:frame];
    if (self) {
        [self addSubview:self.scrollView];
        [self addSubview:self.pageControl];
        
        [self.scrollView addSubview:self.viewOne];
        [self.scrollView addSubview:self.viewTwo];
        [self.scrollView addSubview:self.viewThree];
        [self.scrollView addSubview:self.viewFour];
        
        
        //Done Button
        [self.viewFour addSubview:self.donButton];
    }
    
    return self;
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    CGFloat pageWidth=CGRectGetWidth(self.bounds);
    CGFloat pageFraction=self.scrollView.contentOffset.x/pageWidth;
    self.pageControl.currentPage=roundf(pageFraction);
    
}


#pragma mark 初始化第一个介绍页面
-(UIView *)viewOne{
    if (!_viewOne) {
        _viewOne=[[UIView alloc] initWithFrame:self.frame];
        
        UILabel *titleLabel=[[UILabel alloc] initWithFrame:CGRectMake(0,self.frame.size.height*05, self.frame.size.width*0.8,60)];
        titleLabel.center=CGPointMake(self.center.x,self.frame.size.height*.1);
        titleLabel.text=[NSString stringWithFormat:@"Pixifly"];
        titleLabel.font=[UIFont systemFontOfSize:40.0];
        titleLabel.textColor=[UIColor grayColor];
        titleLabel.textAlignment=NSTextAlignmentCenter;
        titleLabel.numberOfLines=0;
        [_viewOne addSubview:titleLabel];
        
        UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width*.1,self.frame.size.height*.1,self.frame.size.width*.8,self.frame.size.width)];
        imageView.contentMode=UIViewContentModeScaleAspectFit;
        imageView.image=[UIImage imageNamed:@"Intro_Screen_One"];
        [_viewOne addSubview:imageView];
        
        UILabel *descriptionLabel=[[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width*.1,self.frame.size.height*.7,self.frame.size.width*.8,60)];
        descriptionLabel.text=[NSString stringWithFormat:NSLocalizedString(@"Description for First Sceen",nil)];
        descriptionLabel.textColor=[UIColor grayColor];
        descriptionLabel.textAlignment=NSTextAlignmentCenter;
        descriptionLabel.numberOfLines=0;
        [descriptionLabel sizeToFit];
        
        [_viewOne addSubview:descriptionLabel];
        
        CGPoint labelCenter=CGPointMake(self.center.x,self.frame.size.height*.7);
        descriptionLabel.center=labelCenter;
    }
    return _viewOne;
}


-(UIView *)viewTwo{
    
    if(!_viewTwo){
        CGFloat originWidth=self.frame.size.width;
        CGFloat originHeight=self.frame.size.height;
        
        _viewTwo=[[UIView alloc] initWithFrame:CGRectMake(originWidth,0, originWidth, originHeight)];
        
        UILabel *titleLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, self.frame.size.height*.05,self.frame.size.width*.8,60)];
        titleLabel.center=CGPointMake(self.center.x,self.frame.size.height*.1);
        titleLabel.text=[NSString stringWithFormat:NSLocalizedString(@"DropShot",nil)];
        titleLabel.textAlignment=NSTextAlignmentCenter;
        titleLabel.textColor=[UIColor grayColor];
        titleLabel.font=[UIFont systemFontOfSize:40.0];
        titleLabel.numberOfLines=0;
        [_viewTwo addSubview:titleLabel];
        
        UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width*.1,self.frame.size.height*.1,self.frame.size.width*0.8,self.frame.size.width)];
        imageView.contentMode=UIViewContentModeScaleAspectFit;
        imageView.image=[UIImage imageNamed:@"Intro_Screen_Two"];
        [_viewTwo addSubview:imageView];
        
        
        UILabel *descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width*.1, self.frame.size.height*.7, self.frame.size.width*.8, 60)];
        descriptionLabel.text = [NSString stringWithFormat:@"Description for Second Screen."];
        descriptionLabel.font = [UIFont systemFontOfSize:18.0];
        descriptionLabel.textColor = [UIColor grayColor];
        descriptionLabel.textAlignment =  NSTextAlignmentCenter;
        descriptionLabel.numberOfLines = 0;
        [descriptionLabel sizeToFit];
        [_viewTwo addSubview:descriptionLabel];

        CGPoint labelCenter=CGPointMake(self.center.x,self.frame.size.height*.7);
        descriptionLabel.center=labelCenter;
    }
    return _viewTwo;
}

-(UIView *)viewThree{
    if (!_viewThree) {
        CGFloat originWith=self.frame.size.width;
        CGFloat originHeight=self.frame.size.height;
        
        _viewThree=[[UIView alloc] initWithFrame:CGRectMake(originWith*2,0, originWith,originHeight)];
        
        UILabel *titleLabel=[[UILabel alloc] initWithFrame:CGRectMake(0,self.frame.size.height*.05,self.frame.size.width*.8,60)];
        titleLabel.center=CGPointMake(self.center.x,self.frame.size.height*.1);
        titleLabel.text=[NSString stringWithFormat:NSLocalizedString(@"Shaktaya",nil)];
        titleLabel.textColor=[UIColor grayColor];
        titleLabel.font=[UIFont systemFontOfSize:40.0];
        titleLabel.textAlignment=NSTextAlignmentCenter;
        titleLabel.numberOfLines=0;
        [_viewThree addSubview:titleLabel];
        
        
        UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width*.1,self.frame.size.height*.1,self.frame.size.width*.8,self.frame.size.width)];
        imageView.contentMode=UIViewContentModeScaleAspectFit;
        imageView.image=[UIImage imageNamed:@"Intro_Screen_Three"];
        [_viewThree addSubview:imageView];
        
        UILabel *descriptionLabel=[[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width*.1,self.frame.size.height*.7,self.frame.size.width*.8,60)];
        descriptionLabel.textAlignment=NSTextAlignmentCenter;
        descriptionLabel.font=[UIFont systemFontOfSize:18.0];
        descriptionLabel.textColor=[UIColor grayColor];
        descriptionLabel.text=[NSString stringWithFormat:NSLocalizedString(@"Description for Third Screen ",nil)];
        descriptionLabel.numberOfLines=0;
        [descriptionLabel sizeToFit];
        [_viewThree addSubview:descriptionLabel];
        
        CGPoint labelCenter=CGPointMake(self.center.x,self.frame.size.height*.7);
        descriptionLabel.center=labelCenter;
    }
    return _viewThree;
}

-(UIView *)viewFour{
    if (!_viewFour) {
        
        CGFloat originWith=self.frame.size.width;
        CGFloat originHeight=self.frame.size.height;
        
        _viewFour=[[UIView alloc] initWithFrame:CGRectMake(originWith*3,0,originWith, originHeight)];
        UILabel *titleLabel=[[UILabel alloc] initWithFrame:CGRectMake(0,self.frame.size.height*.05,self.frame.size.width*.8,60)];
        titleLabel.center=CGPointMake(self.center.x,self.frame.size.height*.1);
        titleLabel.textColor=[UIColor grayColor];
        titleLabel.font=[UIFont systemFontOfSize:40.0];
        titleLabel.textAlignment=NSTextAlignmentCenter;
        titleLabel.numberOfLines=0;
        titleLabel.text=[NSString stringWithFormat:NSLocalizedString(@"Punctual",nil)];
        
        [_viewFour addSubview:titleLabel];
        
        UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width*.1,self.frame.size.height*.1,self.frame.size.width*.8,self.frame.size.width)];
        imageView.contentMode=UIViewContentModeScaleAspectFit;
        imageView.image=[UIImage imageNamed:@"Intro_Screen_Four"];
        [_viewFour addSubview:imageView];
        
        UILabel *descriptionLabel=[[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width*.1,self.frame.size.height*.7, self.frame.size.width*.8,60)];
        descriptionLabel.text=[NSString stringWithFormat:NSLocalizedString(@"Description for Four Screen ",nil)];
        descriptionLabel.font=[UIFont systemFontOfSize:18.0];
        descriptionLabel.textAlignment=NSTextAlignmentCenter;
        descriptionLabel.textColor=[UIColor grayColor];
        descriptionLabel.numberOfLines=0;
        [descriptionLabel sizeToFit];
        
        [_viewFour addSubview:descriptionLabel];
        
        CGPoint labCenter=CGPointMake(self.center.x,self.frame.size.height*.7);
        descriptionLabel.center=labCenter;
        
        //[_viewFour addSubview:_donButton];
    }
    return _viewFour;
}

-(UIScrollView *)scrollView{
    if (!_scrollView) {
        _scrollView=[[UIScrollView alloc] initWithFrame:self.frame];
        [_scrollView setDelegate:self];
        [_scrollView setPagingEnabled:YES];
        [_scrollView setContentSize:CGSizeMake(self.frame.size.width*4, self.scrollView.frame.size.height)];
        [_scrollView setShowsHorizontalScrollIndicator:NO];
        [self.scrollView setContentOffset:CGPointMake(0,0)];
    }
    return _scrollView;
}

-(UIPageControl *)pageControl{
    if (!_pageControl) {
        _pageControl=[[UIPageControl alloc] initWithFrame:CGRectMake(0,self.frame.size.height-80,self.frame.size.width,10)];
        [_pageControl setCurrentPageIndicatorTintColor:[UIColor colorWithRed:0.129 green:0.588 blue:0.953 alpha:1.000]];
        [_pageControl setNumberOfPages:4];
    }
    return _pageControl;
}

-(UIButton *)donButton{
    if (!_donButton) {
        _donButton=[[UIButton alloc]initWithFrame:CGRectMake(0,self.frame.size.height-60,self.frame.size.width,60)];
        [_donButton setTintColor:[UIColor whiteColor]];
        [_donButton setTitle:@"Let's Go!" forState:UIControlStateNormal];
        [_donButton.titleLabel setFont:[UIFont systemFontOfSize:18.0]];
        [_donButton setBackgroundColor:[UIColor colorWithRed:0.129 green:0.588 blue:0.953 alpha:1.000]];
        [_donButton addTarget:self.delegate action:@selector(onDoneButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    }
    return _donButton;
}
@end
